package com.zdkj.subway.check.controller.subwayRat.conductorDifferences.transferdiff;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.subway.check.dvo.SwCkClearingTransferDiffReasonResultDvo;
import com.zdkj.subway.check.entity.Page;
import com.zdkj.subway.check.result.Result;
import com.zdkj.subway.check.service.impl.subwayRat.transferdiff.SwCkClearingTransferDiffReasonServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 清分及划账数据差异原因表处理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/cleardiff")
@Api(value = "clearingTransferDiffReason", tags = "清分及划账数据差异原因表处理")
public class ClearingTransferDiffReasonController {

    SwCkClearingTransferDiffReasonServiceImpl swCkClearingTransferDiffReasonService;


    /**
     * 查询系统报表清分数据差异原因列表
     *
     * @return
     */
    @ApiOperation(value = "系统报表清分数据差异原因列表", notes = "分页查询系统报表清分数据差异原因列表", hidden = true)
    @GetMapping("/getTransferDiffList")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "searchDate", value = "查询日期：yyyy-MM-dd", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "diffSource", value = "差异来源类型 1. 单程票-应收-实收统计 2.二维码应收-应付差异统计 3.	人脸电子票应收应付差异统计", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "sendStatus", value = "下发状态 1：已下发 0：未下发", dataTypeClass = Integer.class)
            }
    )
    public Page getTransferDiffList(Page page, String searchDate, String diffSource, Integer sendStatus) {
        String ids = null;
        List<SwCkClearingTransferDiffReasonResultDvo> serviceTransferDiffList = swCkClearingTransferDiffReasonService.getTransferDiffList(page, ids, searchDate, diffSource, sendStatus);
        page.setData(serviceTransferDiffList);
        return page;
    }

    /**
     * 批量完善差异原因
     * @param jsonObject
     * @return
     */
    @ApiOperation(value = "批量完善差异原因", notes = "批量完善差异原因", hidden = true)
    @PostMapping("/saveMutilCleardDiff")
    public Result saveMutilCleardDiff(@RequestBody JSONObject jsonObject) {
        //{"thisday":"2020-12-20","diffdesc":"qwe","ids":[3]}
        return swCkClearingTransferDiffReasonService.saveMutilCleardDiff(jsonObject);
    }

    /**
     * 批量下发差异
     * @param jsonObject
     * @return
     */
    @ApiOperation(value = "批量下发差异", notes = "批量下发差异，更新状态", hidden = true)
    @PostMapping("/sendMutilCleardDiff")
    public Result sendMutilCleardDiff(@RequestBody JSONObject jsonObject) {
        //{"ids":[3]}
        return swCkClearingTransferDiffReasonService.sendMutilCleardDiff(jsonObject);
    }

    /**
     * 差异原因导入
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "差异原因导入", notes = "差异原因导入回显")
    @PostMapping(value = "/saveDiffBatchList")
    public Result saveDiffBatchList(@RequestParam(value = "file") MultipartFile file) throws Exception {
        return swCkClearingTransferDiffReasonService.saveBatchWithExcel(file);
    }

    /**
     * 差异原因导入
     * @param jsonArray
     * @return
     */
    @ApiOperation(value = "差异原因导入", notes = "差异原因导入")
    @PostMapping(value = "/saveDiffBatch")
    public Result saveBatch(@RequestBody JSONArray jsonArray) {
        return swCkClearingTransferDiffReasonService.saveBatch(jsonArray);
    }

    /**
     * 导出
     * @param
     * @return
     */
    @ApiOperation(value = "导出", notes = "导出")
    @GetMapping({"/export"})
    @SysLog("清分及划账数据差异原因表-导出")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "diffSource", value = "差异来源类型 1. 单程票-应收-实收统计 2.二维码应收-应付差异统计 3.人脸电子票应收应付差异统计", dataTypeClass = String.class,required = true),
                    @ApiImplicitParam(name = "searchDate", value = "日期", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "sendStatus", value = "发送状态", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "ids", value = "id", dataTypeClass = String.class),
            }
    )
    public void export(String ids, String searchDate, String diffSource, Integer sendStatus, HttpServletResponse response) {
        swCkClearingTransferDiffReasonService.export(ids, searchDate, diffSource, sendStatus,response);
    }
}
